<?php 
	require_once("init.php"); 
?>

<?php
	$qMyTopicsOpen = mysql_query("
    SELECT count(topicId) AS totalCount FROM topics
    WHERE statusId = ".$statusActive." 
			AND now() < dateClosed 
			AND userId = ".$_SESSION["userId"]."
	");
	$nMyTopicsOpen = mysql_fetch_array($qMyTopicsOpen);
	$nMyTopicsOpen = $nMyTopicsOpen["totalCount"];
			
	$qMyTopicsLast7Days = mysql_query("
    SELECT count(topicId) AS totalCount FROM topics
    WHERE statusId = ".$statusActive." 
			AND userId = ".$_SESSION["userId"]." AND now() >= dateClosed
			AND dateClosed >= subDate(now(), INTERVAL 7 DAY)
	");
	$nMyTopicsLast7Days = mysql_fetch_array($qMyTopicsLast7Days);
	$nMyTopicsLast7Days = $nMyTopicsLast7Days["totalCount"];
	
	$qMyTopicsThisMonth = mysql_query("
    SELECT count(topicId) AS totalCount FROM topics
    WHERE statusId = ".$statusActive." 
			AND userId = ".$_SESSION["userId"]." AND now() >= dateClosed
			AND dateClosed >= subDate(last_day(now()), INTERVAL dayOfMonth(last_day(now()))-1 DAY)
			AND dateClosed < addDate(last_day(now()), INTERVAL 1 DAY)
	");
	$nMyTopicsThisMonth = mysql_fetch_array($qMyTopicsThisMonth);
	$nMyTopicsThisMonth = $nMyTopicsThisMonth["totalCount"];
	
	$qMyTopicsLast3Months = mysql_query("
    SELECT count(topicId) AS totalCount FROM topics
    WHERE statusId = ".$statusActive." 
			AND userId = ".$_SESSION["userId"]." AND now() >= dateClosed
			AND dateClosed >= subDate(subDate(last_day(now()), INTERVAL dayOfMonth(last_day(now()))-1 DAY), INTERVAL 3 MONTH)
      AND dateClosed < subDate(addDate(last_day(now()), INTERVAL 1 DAY), INTERVAL 1 MONTH)
	");
	
	$nMyTopicsLast3Months = mysql_fetch_array($qMyTopicsLast3Months);
	$nMyTopicsLast3Months = $nMyTopicsLast3Months["totalCount"];
?>

<ul id="mytopics" title="My Topics" showToolbarButton="true" toolbarButtonText="New Topic" toolbarButtonHREF="#submitTopicForm">
  <li><a href="myclosedtopics.php?range=last7days">Last 7 days <?php if ($nMyTopicsLast7Days > 0) print "<small>(".$nMyTopicsLast7Days.")</small>"; ?></a></li>
  <li><a href="myopentopics.php">Open <?php if ($nMyTopicsOpen > 0) print "<small>(".$nMyTopicsOpen.")</small>"; ?></a></li>
  <li><a href="myclosedtopics.php?range=thismonth">Closed this month <?php if ($nMyTopicsThisMonth > 0) print "<small>(".$nMyTopicsThisMonth.")</small>"; ?></a></li>
  <li><a href="myclosedtopics.php?range=last3months">Closed last 3 months <?php if ($nMyTopicsLast3Months > 0) print "<small>(".$nMyTopicsLast3Months.")</small>"; ?></a></li>
  <li><a href="myclosedtopics.php?range=oldtopics">Old topics</a></li>
</ul>